package cn.liontalk.controller;

import cn.liontalk.common.result.CodeMsg;
import cn.liontalk.common.result.Result;
import cn.liontalk.entity.OrderInfo;
import cn.liontalk.entity.User;
import cn.liontalk.service.GoodsService;
import cn.liontalk.service.OrderService;
import cn.liontalk.vo.GoodsVO;
import cn.liontalk.vo.OrderInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: 周哲
 * @package: cn.liontalk.controller
 * @description:
 * @date: 2019/1/23 14:43
 * @version: V1.0
 */

@Controller
@RequestMapping(value = "/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private GoodsService goodsService;

    @ResponseBody
    @RequestMapping(value = "/detail/{orderId}", method = RequestMethod.GET)
    public Result <OrderInfoVO> getOrderDetailInfo(@PathVariable("orderId") Long orderId, User user) {
        OrderInfo orderInfo = new OrderInfo();
        if (user == null) {
            return Result.error(CodeMsg.SESSION_ERROR);
        }
        OrderInfo order = orderService.getOrderDetailInfoById(orderId);
        if (order == null) {
            return Result.error(CodeMsg.ORDER_NOT_EXIST);
        }
        GoodsVO goodsVO = goodsService.queryGoodsById(order.getGoodsId());
        OrderInfoVO orderInfoVO = new OrderInfoVO();
        orderInfoVO.setOrderInfo(orderInfo);
        orderInfoVO.setGoodsVO(goodsVO);
        return Result.success(orderInfoVO);
    }
}
